﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using OA.Model;
using OA.DBUtility;
using System.Collections.Generic;

namespace OA.Manager
{
	/// <summary>
	/// 数据访问类:Dept
	/// </summary>
	public class DeptManager
	{
		 private SqlService<DeptInfo> _sqlService = null;

         public DeptManager()
		{
            _sqlService = new SqlService<DeptInfo>();
        }

         public DeptManager(string connectionString)
         {
             _sqlService = new SqlService<DeptInfo>(connectionString);
         }

		#region  Method		

        /// <summary>
        /// 插入新记录
        /// </summary>
        /// <param name="deptInfo"></param>
        /// <returns></returns>
        public bool InsertDeptInfo(DeptInfo deptInfo)
        {
            return _sqlService.SaveEntity(deptInfo);
        }

        /// <summary>
        /// 根据打印任务ID获得打印任务信息
        /// </summary>
        /// <param name="taskID"></param>
        /// <returns></returns>
        public DeptInfo GetDeptInfoByID(int ID)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("ID", ID);
            return _sqlService.GetSingleByFields(dic, null);
        }

        public List<DeptInfo> GetAllDept()
        {
            return _sqlService.GetAllByFields(null, null,-1);
        }

        /// <summary>
        /// 判断该打印任务是否存在
        /// </summary>
        /// <param name="deptInfo"></param>
        /// <returns></returns>
        public bool IsExistDeptInfo(DeptInfo deptInfo)
        {
            return _sqlService.IsExist(deptInfo);
        }

        /// <summary>
        /// 根据指定的字段更新，字段名是数据库中对应的名称
        /// </summary>
        /// <param name="deptInfo"></param>
        /// <param name="needUpdateFields"></param>
        /// <returns></returns>
        public bool UpdateDeptInfo(DeptInfo deptInfo, List<string> needUpdateFields)
        {
            return _sqlService.UpdateByFields(deptInfo, needUpdateFields);
        }

        /// <summary>
        /// 删除该检查任务
        /// </summary>
        /// <param name="deptInfo"></param>
        /// <returns></returns>
        public bool DeleteDeptInfo(DeptInfo deptInfo)
        {
            return _sqlService.DeleteEntity(deptInfo);
        }
		
		#endregion  Method
	}
}

